<?
	session_start();
	ob_start();
	//global $TRDF;
	if(empty($_SESSION['user_login'])){
		echo"
		<br><br><br><br><br>
		<div align=center style='font-family: verdana; font-size: 10px; color: red;'>
		 Maaf, Halaman ini tidak bisa diakses. <br>
		 <a href='../index.php'>Anda harus login terlebih dahulu.</a><br><br><BR>
		 <span style='color:black;'>Aplikasi SDM, PT.Surveyor Indonesia</span>
		</div>
		";
		exit();
	}

	if($HTTP_GET_VARS['excel'] == "yes"){
	}
	else{
	?>
<link rel="stylesheet" type="text/css" href="../style/style.css">
	<?
    }
	?>
<title>Laporan Cuti Besar</title>
<?
include("../lib/config.php");
$show		= $HTTP_GET_VARS['show'];
$periode	= $HTTP_GET_VARS['periode'];
$divisi		= $HTTP_GET_VARS['divisi'];

// get divisi
if($divisi == "ALL"){
	//
}
else{
	$sql = mssql_query("SELECT * FROM VLevelCabang WHERE kode_so='$divisi'",$conn);
	$row = mssql_fetch_array($sql);
}
?>
<span style="font-size:14px;"><b>LAPORAN CUTI BESAR</b></span><br>
<span style="font-size:12px;">Divisi/Biro/Cabang : 
<?
if($divisi == "ALL"){
	echo"Semua";
}
else{
	echo"$row[uraian] - $row[AreaCode]";
}
?>
</span><br>
<span style="font-size:12px;">Periode ke- <?=$periode?></span>
<div style="font-size:12px;" align="right">
<table width="100%">
 <tr>
  <td width="75%">
  <?
	if($HTTP_GET_VARS['excel'] == "yes"){
	}
	else{
  ?>
	<div style="color:blue;" class="print_ignore">
  [ <a href="Javascript:window.print();">Cetak</a> | <a href="<?=$PHP_SELF?>?show=<?=$show?>&amp;periode=<?=$periode?>&amp;divisi=<?=$divisi?>&amp;excel=yes">Export Excel</a> ]
	</div>  
	<?
	}
    ?>
  </td>
  <td width="25%" align="right">Tgl. Cetak : <?=date("d/m/Y")?></td>
 </tr>
</table>
</div>
<hr noshade size="-2">
<table width="100%" border="1">
 <tr bgcolor="#CCCCCC" style="font-weight:bold;">
  <td rowspan="2" align="center">No.</td>
  <td rowspan="2" align="center">NIK</td>
  <td rowspan="2" align="center">Nama</td>
  <?
  if($divisi == "ALL"){
  	echo"<td rowspan=2>Divisi/Biro/Cabang</td>";
  }
  ?>
  <td rowspan="2" align="center">Jabatan</td>
  <td colspan="2" align="center">Jatah Cuti</td>
  <td rowspan="2" align="center">Jml Cuti</td>
  <td rowspan="2" align="center" width="50">Cuti Sudah Diambil</td>
  <td rowspan="2" align="center">Saldo</td>
 </tr>
 <tR bgcolor="#CCCCCC" style="font-weight:bold;">
  <td  align="center">Awal</td>
  <td  align="center">Akhir</td>
 </tR>
<?
	// get status karyawan akrif dari setiap divisi
	// U dan H adalah jenis surat PHK atau pengunduran diri
	// 123456789123
	// 0123456
	if($divisi == "ALL"){
		$sqlget = mssql_query("WITH CUTI_BESAR AS (SELECT (YEAR(getdate())-YEAR(tgl_efektif))/6 besar, (year(getdate())-YEAR(tgl_efektif)) sisa_tahun,year(tgl_efektif) masuk,year(getdate()) skrg, A.NIK,A.Nama,kode_so1,kode_so2,jabatan1,jabatan2 FROM VLatestKarir A, Karyawan B WHERE Jenis NOT IN ('U','H') AND A.NIK=B.NIK ) SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM CUTI_BESAR WHERE besar='".$periode."' ",$conn);
	}
	else{
		//$sqlget = mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY A.NIK) AS No, * FROM VRepEmpStatus A, Karyawan B WHERE StatusKaryawan NOT IN ('U','H') AND (substring(kode_so1,1,7)='".substr($divisi,0,7)."' OR substring(kode_so2,1,7)='".substr($divisi,0,7)."') AND A.NIK=B.NIK",$conn);	
		$sqlget = mssql_query("WITH CUTI_BESAR AS (SELECT (YEAR(getdate())-YEAR(tgl_efektif))/6 besar, (year(getdate())-YEAR(tgl_efektif)) sisa_tahun,year(tgl_efektif) masuk,year(getdate()) skrg, A.NIK,A.Nama,kode_so1,kode_so2,jabatan1,jabatan2 FROM VLatestKarir A, Karyawan B WHERE Jenis NOT IN ('U','H') AND A.NIK=B.NIK AND (substring(kode_so1,1,7)='".substr($divisi,0,7)."' OR substring(kode_so2,1,7)='".substr($divisi,0,7)."')) SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM CUTI_BESAR WHERE besar='".$periode."' ",$conn);
	}
	while($rowget = mssql_fetch_array($sqlget)){
		echo"
		 <tr>
		  <td align=right>$rowget[No]</td>
		  <td>$rowget[NIK]</td>
		  <td>$rowget[Nama]</td>";
		  
		if($divisi == "ALL"){
		if(empty($rowget[kode_so1])){
			$kodeso =$rowget[kode_so2];
		}
		else{
			$kodeso =$rowget[kode_so1];
		}
		 
		$sql9 = mssql_query("SELECT * FROM VLevelCabang WHERE substring(kode_so,1,7)='".substr($kodeso,0,7)."'",$conn);
		$row9 = mssql_fetch_array($sql9);
		echo"<td>";
		if(empty($row9[uraian])){
			echo"&nbsp;";
		}
		else{
			echo"$row9[uraian]";
		}
		echo"</td>";
			//echo"<td rowspan=2>Divisi/Biro/Cabang</td>";
		  }
		  
		echo"<td>
		  ";
		// get jabatan
			if(empty($rowget[jabatan1])){
				$jabatan = $rowget[jabatan2];
			}
			else{
				$jabatan = $rowget[jabatan1];
			}
		
		if(!empty($jabatan)){
			$sqljab = mssql_query("SELECT * FROM MstJabatan WHERE kode='$jabatan'",$conn);
			if(mssql_num_rows($sqljab) > 0){
			$rowjab = mssql_fetch_array($sqljab);
			}
			echo"$rowjab[jabatan]";
		}
		else{
			echo"&nbsp;";
		}
		
		// get jumlah cuti
			$gj = mssql_query("SELECT jatah_cuti, syarat_waktu FROM VJCuti WHERE nama='Cuti Besar'",$conn);
			$rj = mssql_fetch_array($gj);
			$jatah_cuti = $rj[jatah_cuti];
		// jumlah cuti yang sudah diambil
			$sqlsisa 	= mssql_query("SELECT count(*) jumlah FROM Cuti WHERE NIK='$rowget[NIK]' AND periode='".$periode."' AND aktif IN ('A',NULL)",$conn);
			$cntsisa 	= mssql_fetch_array($sqlsisa);
		// saldo
			$saldo		= ($jatah_cuti-$cntsisa[0]);

		///////////
		/////////// DITAMPILKAN JIKA PEGAWAI SUDAH MENGAMBIL JATAH BESAR
		///////////////
		// get data from karir ptsi (Tanggal Masuk)
		$sawalkarir = mssql_query("SELECT CONVERT(CHAR(12), tgl_efektif, 103) TglEfektif FROM VKarirPtsi WHERE NIK='".$rowget[NIK]."' ORDER BY seqno ASC",$conn);
		$rawalkarir = mssql_fetch_array($sawalkarir);	
		// akhir batas cuti tahunan
		// tgl bulan
		$startdm = substr($rawalkarir[TglEfektif],0,5);
		// tanggal
		$std	 = substr($rawalkarir[TglEfektif],0,2);
		$stm	 = substr($rawalkarir[TglEfektif],3,2);
		$endyear = substr($rawalkarir[TglEfektif],6,4);
		
		//if(empty($cntsisa[0])){
			//$Awal	= "&nbsp;";
			//$Akhir 	= "&nbsp;";			
		//}	
		//else{
			$tglmasuk = $rawalkarir[TglEfektif];
			// get DD/MM
			// get periode
			// 2005 - 2006
			// 01234567891
			
			// 01-12-2006
			// 30-11-2006
			
			if(($std-1) == 0){
				switch($stm){
					case "01":
						$std = "31";
						$stm = "12";
						break;
					case "02":
						$std = "28";
						$stm = ($stm-1);
						break;
					case "03":
						$std = "31";
						$stm = ($stm-1);
						break;
					case "04":
						$std = "30";
						$stm = ($stm-1);
						break;
					case "05":
						$std = "31";
						$stm = ($stm-1);
						break;
					case "06":
						$std = "30";
						$stm = ($stm-1);
						break;
					case "07":
						$std = "31";
						$stm = ($stm-1);
						//$stm = $stm;
						break;
					case "08":
						$std = "31";
						$stm = ($stm-1);
						break;
					case "09":
						$std = "30";
						$stm = ($stm-1);
						break;
					case "10":
						$std = "31";
						$stm = ($stm-1);
						break;
					case "11":
						$std = "30";
						$stm = ($stm-1);
						break;
					case "12":
						$std = "31";
						$stm = ($stm-1);
						break;
				}
			}
			else{
				$std = ($std-1);
				if($std < 10){
					$std = "0".$std;
				}
				$stm = $stm;
			}
			
			$ddmm	= substr($tglmasuk,0,6);
			$Awal	= $ddmm.($endyear+($periode*6)-6);
			
			if($stm < 10){
				$stm = $stm;
			}
			else{
				$stm = $stm;
			}		
				
			$Akhir 	= $std."/".$stm."/".($endyear+($periode*6))."";
		//}
		
		echo"
		  </td>  
		  <td align=center>$Awal</td>
		  <td align=center>$Akhir</td>";
		echo"
		 <td align=center>$jatah_cuti</td>
		 <td align=center>$cntsisa[0]</td>
		 <td align=center>$saldo</td>
		 </tr>
		";
	}
?> 
</table>
<?

//*///
if($HTTP_GET_VARS['excel'] == "yes"){
	header('Content-type: application/vnd.ms-excel');
	header("Content-Disposition: attachment; filename=ReportCutiBesar$periode$divisi.xls");
	header("Pragma: no-cache");
	header("Expires: 0");
	}
else{

}
?>
